package com.baizhi.service.impl;

import com.baizhi.dao.CityDAO;
import com.baizhi.entity.City;
import com.baizhi.service.CityService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class CityServiceImpl extends ServiceImpl<CityDAO,City> implements CityService {
    @Autowired
    private CityDAO cityDAO;

    @Override
    public List<City> queryAll() {
        List<City> cities = cityDAO.selectList(null);
        return cities;
    }

    @Override
    public City add(String name) {
        City city = new City();
        city.setName(name);
        int insert = cityDAO.insert(city);
        LambdaQueryWrapper<City> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(City::getName,name);
        City citys = cityDAO.selectOne(queryWrapper);
        return citys;
    }

    @Override
    public City queryById(Long id) {
        LambdaQueryWrapper<City> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(City::getId,id);
        City city = cityDAO.selectOne(queryWrapper);
        return city;
    }
}
